package com.zero.zutils
{
	public class ObjectUtils
	{
		public function ObjectUtils()
		{
		}
		
		public static function combineXML(result:XML,data:XML):void
		{
			if(data == null || result == null)
			{
				return;
			}
			var attr:XMLList =data.attributes();
			for each(var item:XML in attr)
			{
				var propname:String = item.name().toString();
				var value:String = item.toString();
				if(!result.hasOwnProperty("@"+propname))
				{
					result["@"+propname] = value;
				}
			}
		}
		
		/**
		 * 
		 * 通过XML对目标对象进行赋值
		 * @param object: 赋值的目标对象
		 * @param data : 保存属性的XML对象
		 * 
		 */		
		public static function copyPorpertiesByXML(object:Object,data:XML):void
		{
			if(object.hasOwnProperty("beginChanges"))object["beginChanges"]();
			var attr:XMLList =data.attributes();
			for each(var item:XML in attr)
			{
				var propname:String = item.name().toString();
				if(object.hasOwnProperty(propname))
				{
					var value:String = item.toString();
					if(value == "false")
					{
						object[propname] = false;
					}else
					{
						object[propname] = value;
					}
				}
			}
			if(object.hasOwnProperty("commitChanges"))object["commitChanges"]();
		}
	}
}